import dt from '@dt/dt'
import paramsMgr from '@/biz/bonus/params.js'

function value(_this) {
  if (_this.info.defaultCounselorSellersSomeWay == '2') {
    return [{
      key: 'defaultCounselorSellersSomeWayValue',
      col: 8,
      placeholder: '请输入固定提点',
      input: {
        type: 'number',
        min: 0,
      }
    }, {
      placeholder: '万分之',
      col: 6,
      text: {}
    }]
  } else {
    return []
  }
}

function options(_this) {
  function group() {
    return [
      {
        key: 'defaultCounselorSellersSomeWay',
        col: 10,
        select: {
          key: 'baseMentionSomething2'
        },
        change: () => {
          opt[0][0].group = group()
        }
      },
      ...value(_this)
    ]
  }
  
  let opt = [
    [{
      title: '默认非顾问卖房提点设置',
      col: 14,
      group: group()
    }, {
      col: 3,
      button: {
        title: '新增岗位设置',
        type: 'primary',
        ghost: true,
        click: () => {
          _this.list.push({
            postIds: [],
            someWay: '1',
            someWayValue: 0
          })
        }
      }
    }],
  ]
  return opt
}

function columns(_this, flag) {
  return [{
      type: 'index',
      title: '序号',
      width: 60
    },
    {
      title: '岗位',
      cell: (row) => {
        let options = paramsMgr.positions(_this.list, row)
        options = options.filter(i => i.value != '置业顾问')
        return {
          edit: {
            key: 'postIds',
            placeholder: '请选择岗位(多选)',
            select: {
              options,
              multiple: true,
              maxTagCount: 1
            }
          }
        }
      }
    },
    {
      title: '提点设置',
      width: 360,
      cell: (row) => {
        let group = [{
          key: 'someWay',
          col: 11,
          select: {
            key: 'baseMentionSomething2'
          }
        }]
        if (row.someWay == '2') {
          group.push({
            key: 'someWayValue',
            col: 9,
            placeholder: '请输入固定提点',
            input: {
              type: 'number',
              min: 0
            },
          }, {
            placeholder: '万分之',
            col: 4,
            text: {}
          })
        }
        return {
          group
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: 70,
      cell: (row) => {
        return {
          btn: [{
            title: '删除',
            event: 'onDelete',
          }]
        }
      }
    }
  ]
}

function helps() {
  return [{
      label: '非顾问卖房奖金设置',
      value: ['设置后，非顾问岗位作为签约人，按配置提点结算佣金']
    }, {
      label: '默认非顾问卖房提点设置',
      value: [
        '配置后，所有非顾问岗位按此配置计算',
        '设置为“置业顾问最高提点”，则结算奖金=结算总销*该项目下置业顾问最高提点',
        '设置为“固定提点”，则结算奖金=本次结算总销*固定提点，注：设置为固定提点后，发放标准、职级点数、职级跳点不再适用'
      ]
    }, {
      label: '新增岗位设置',
      value: ['可选择不同岗位设置不同的提点，未设置的岗位按默认非顾问卖房提点计算']
    }, {
      label: '参考配置',
      value: ['非顾问其他岗位按“置业顾问最高提点”计算奖金']
    }, {
      tips: '以上配置在保存后即时生效，不影响已发起奖金单',
    },
  ]
}

export default {
  options,
  columns,
  helps
}
